#!/usr/bin/env python
# -*- coding:utf8 -*-
# uncompyle6 version 2.15.1
# Python bytecode 2.7 (62211)
# Decompiled from: Python 2.7.10 (default, Jul  1 2017, 13:36:56) 
# [GCC 4.4.6 20110731 (Red Hat 4.4.6-4)]
# Embedded file name: ./paas/api/decorators.py
# Compiled at: 2017-11-16 15:44:28
from django.http import JsonResponse
from django.utils.decorators import available_attrs
try:
    from functools import wraps
except ImportError:
    from django.utils.functional import wraps

from django.conf import settings
from api.utils import InnerFeedback

def esb_required():

    def decorator(view_func):

        @wraps(view_func, assigned=available_attrs(view_func))
        def _wrapped_view(request, *args, **kwargs):
            feedback = InnerFeedback()
            x_app_token = request.META.get('HTTP_X_APP_TOKEN')
            x_app_code = request.META.get('HTTP_X_APP_CODE')
            if not (x_app_code == 'esb' and x_app_token == settings.ESB_TOKEN):
                feedback['result'] = False
                feedback['message'] = u'ESB鉴权失败'
                feedback['code'] = '1001'
                return JsonResponse(feedback)
            return view_func(request, *args, **kwargs)

        return _wrapped_view

    return decorator
